

/*
 * ******************************************************
 * post数据
 * ******************************************************
 */
function postData(url, mdata, callback){
    var $callback = callback || ajaxDone;
    if (!$.isFunction($callback)) 
        $callback = eval('(' + callback + ')');
    $.ajax({
        type: 'POST',
        url: url,
        data: mdata,
        dataType: "json",
        cache: false,
        success: $callback,
        error: ajaxError
    });
}

/*
 * ******************************************************
 * post表单
 * ******************************************************
 */
function postForm(form_id, callback){
    var $form = $('#' + form_id);
    $.ajax({
        type: 'POST',
        url: $form.attr("action"),
        data: $form.serializeArray(),
        dataType: "json",
        cache: false,
        success: callback || ajaxDone,
        error: ajaxError
    });
    return false;
}

function ajaxDone(jdata){

}

function ajaxError(jdata){
    alert(jdata.message);
}

/*
 * ******************************************************
 * 页面跳转
 * ******************************************************
 */
function go2(url){
    if (typeof(url) == 'undefined' || url == 0) {
        window.location.reload();
    }
    else {
        window.location.href = url;
    }
}

/*
 * ******************************************************
 * 首页最新特价轮播
 * ******************************************************
 */
function promote_good_slide(forward){
    var showul = $('#promote_box ul:visible').index();
    var nowshow = showul + forward;
    if (nowshow > 2) 
        nowshow = 0;
    if (nowshow < 0) 
        nowshow = 2;
    $('#promote_box ul:visible').hide();
    $('#promote_box ul:eq(' + nowshow + ')').show();
}

/*
 * ******************************************************
 * 将当前浏览商品记录到cookie
 * ******************************************************
 */
function add_recent_view(good_id, good_img, good_url, good_name){
    var recent_view = $.cookie('recent_view');
    var views = new Array(0);
    if (recent_view != null) {
        var views = recent_view.split("<|>");
        var is_ext = $.cookie('view_' + good_id);
        if (is_ext != null) 
            return false;
    }
    $.cookie('view_' + good_id, good_id);
    $.cookie('view_' + good_id + '_url', good_url);
    $.cookie('view_' + good_id + '_img', good_img);
    $.cookie('view_' + good_id + '_name', good_name);
    if (views.length >= 6) {
        var delview = views.shift();
        var items = delview.split(">|<");
        $('#recent_good_' + $.cookie('view_' + items[0])).remove();
        $.cookie('view_' + items[0], null);
        $.cookie('view_' + items[0] + '_url', null);
        $.cookie('view_' + items[0] + '_img', null);
        $.cookie('view_' + items[0] + '_name', null);
    }
    $('#recent_views').append('<li id="recent_good_' +
    $.cookie('view_' + good_id) +
    '"><a href="' +
    $.cookie('view_' + good_id + '_url') +
    '"><img src="' +
    $.cookie('view_' + good_id + '_img') +
    '" width="80" height="80" /></a></li>');
    var newview = good_id + '>|<' + good_url + '>|<' + good_img
    views.push(newview);
    var recent_view = views.join('<|>');
    $.cookie('recent_view', recent_view);
}

/*
 * ******************************************************
 * 显示最近浏览浏览商品
 * ******************************************************
 */
function get_recent_views(){
    var recent_view = $.cookie('recent_view');
    if (recent_view == null) 
        return false;
    var views = recent_view.split("<|>");
    var newviews = new Array();
    $.each(views, function(i, iview){
        var items = iview.split(">|<");
        if ($.cookie('view_' + items[0]) != null) {
            $('#recent_views').append('<li id="recent_good_' +
            $.cookie('view_' + items[0]) +
            '"><a href="' +
            $.cookie('view_' + items[0] + '_url') +
            '"><img src="' +
            $.cookie('view_' + items[0] + '_img') +
            '" width="80" height="80" alt=' +
            $.cookie('view_' + items[0] + '_name') +
            ' /></a></li>');
            newviews.push(iview);
        }
        else {
            $.cookie('view_' + items[0], null);
            $.cookie('view_' + items[0] + '_url', null);
            $.cookie('view_' + items[0] + '_img', null);
            $.cookie('view_' + items[0] + '_name', null);
        }
    });
    var recent_view = newviews.join('<|>');
    $.cookie('recent_view', recent_view);
}

/*
 * ******************************************************
 * 帮助页面
 * ******************************************************
 */
function help_show(me){
    var nowhelpshow = $('.small_list:visible');
    var show_id = $('#' + $(me).attr('rel'));
    if (show_id.is(':hidden')) {
        show_id.fadeIn();
        nowhelpshow.hide();
        nowhelpshow.prev('h3').removeClass('open').addClass('close');
        $(me).addClass('open').removeClass('close');
    }
}
function ChangeSelect(ParentValue, NextId, NextSelectedValue, ArrObj,DefaultStr)  
{  
    StrObj = eval(document.getElementById(NextId));  
    StrObj.length = 0;  
    //判断它是二级数据源，还是三级  
    if (ArrObj.length > 0)  
    {  
        if (ArrObj[0].length == 2)  
        {ArrNum = 0;}  
        else  
        {ArrNum = 2;}  
    }  
    //显示所有列表  
    for (i = 0; i < ArrObj.length; i++)  
    {  
        if (i == 0)  
        {  
            if (DefaultStr == undefined ) DefaultStr="-请选择-";  
            StrObj.options[StrObj.length] = new Option(DefaultStr, "");  
        }  
        if (ArrObj[i][1] == ParentValue)  
        {  
            StrObj.options[StrObj.length] = new Option(ArrObj[i][0],ArrObj[i][ArrNum]);  
        }  
    }  
    //选中列表内某一项  
    for (i = 0; i < StrObj.length; i++)  
    {  
        if (StrObj.options[i].value == NextSelectedValue)  
        {  
            StrObj.options[i].selected = true;  
        }  
    }  
    //激发下一级的onchange事件以实现多级级联  
    StrObj.onchange();  
} 

/*
 * ******************************************************
 * ajax页面
 * ******************************************************
 */
function ajaxpage(me){
 	var murl = $(me).attr('url');
	var mrel = $(me).attr('rel');
	$.ajax({
	   type: "GET",
	   url: murl,
	   success: function(msg){
	     $('#'+ mrel).replaceWith(msg);
	   }
	});
}